package com.attendance.chdingtask.utils.dingApi;

import com.dingtalk.api.DefaultDingTalkClient;
import com.dingtalk.api.DingTalkClient;
import com.dingtalk.api.request.OapiV2DepartmentGetRequest;
import com.dingtalk.api.response.OapiV2DepartmentGetResponse;
import com.taobao.api.ApiException;

import java.util.UUID;

public class DeptHelper {

    public static void main(String[] args) throws ApiException {
        System.out.println(UUID.randomUUID().toString().replace("-",""));
    }

    public static OapiV2DepartmentGetResponse.DeptGetResponse getDeptResponse(Long deptId, String accessToken) throws ApiException {
        DingTalkClient client= new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/department/get");
        OapiV2DepartmentGetRequest req = new OapiV2DepartmentGetRequest();
        req.setDeptId(deptId);
        req.setLanguage("zh_CN");
        OapiV2DepartmentGetResponse rsp = client.execute(req, accessToken);
        if(!rsp.isSuccess()){
            throw new ApiException("获取部门详情异常:"+"-----部门id:"+deptId+"-----"+rsp.getErrmsg());
        }
        return rsp.getResult();

    }
}
